package com.dragon.app.ykd.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.dragon.app.ykd.constant.ApplyNode;
import com.dragon.app.ykd.dto.AcLoanApplyNode;
import com.dragon.loan.repository.AcLoanApplyNodeMapper;
import com.marvels.common.utils.ServerProperties;

import cn.hutool.core.util.StrUtil;

/**
 * 节点流程服务类
 * 
 * @title AcLoanApplyNodeServiceImpl
 * @author tuxu
 * @date 2018年10月11日
 */
@Service("acLoanApplyNodeService")
public class AcLoanApplyNodeServiceImpl implements AcLoanApplyNodeService {
	
	@Autowired
	private AcLoanApplyNodeMapper acLoanApplyNodeMapper;

	@Value("${config.properties.path}")
	private  String configPropertiesPath;
	
	@Override
	public int insertSelective(AcLoanApplyNode acLoanApplyNode) {
		return acLoanApplyNodeMapper.insertSelective(acLoanApplyNode);
	}

	@Override
	public int insertSelective(String loanId, ApplyNode applyNode) {
		AcLoanApplyNode acLoanApplyNode = new AcLoanApplyNode();
		acLoanApplyNode.setLoanId(loanId);
		acLoanApplyNode.setNodeCode(applyNode.getCode());
		acLoanApplyNode.setNodeMsg(applyNode.getMsg());
		return insertSelective(acLoanApplyNode);
	}

	@Override
	public AcLoanApplyNode queryLastApplyNode(String loanId) {
		AcLoanApplyNode acLoanApplyNode = acLoanApplyNodeMapper.queryLastApplyNode(loanId);
		return acLoanApplyNode;
	}

	@Override
	public List<AcLoanApplyNode> queryApplyNode(AcLoanApplyNode acLoanApplyNode) {
		return acLoanApplyNodeMapper.queryApplyNode(acLoanApplyNode);
	}

	@Override
	public boolean isGoAlipay() {
		boolean goAlipay = true;
		String isGoAlipay  = ServerProperties.getValue(configPropertiesPath, "common.properties", "is_go_alipay");
		// 满足条件则不走支付宝
		if(StrUtil.isNotEmpty(isGoAlipay) && "false".equals(isGoAlipay)){
			goAlipay = false;
		}
		return goAlipay;
	}

}
